/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Car_types;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Mr.aUgust
 */
public class DALtbl_Car_types extends BaseConnection{
    CallableStatement clbStm=null;
    ResultSet rs=null;
      public boolean addtbl_Car_types(Etbl_Car_types obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_types_add(?,?)}");
            clbStm.setString("name", obj.getName());                        
            clbStm.setString("description", obj.getDescription());                     
            clbStm.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_types.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean edittbl_Car_types(Etbl_Car_types obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_types_update(?,?,?)}");
            clbStm.setInt("cartype_Id",obj.getCartype_Id());
            clbStm.setString("name", obj.getName());                        
            clbStm.setString("description", obj.getDescription());             
            clbStm.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_types.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean deletetbl_Car_types(int cartype_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_types_delete(?)}");
            clbStm.setInt("cartype_Id",cartype_Id);              
            clbStm.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_types.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      public Etbl_Car_types getOne_CarType(int Cartype_id){
        Etbl_Car_types oCarType= new Etbl_Car_types();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_types_get(?)}");
            clbStm.setInt("cartype_Id", Cartype_id);
            rs=clbStm.executeQuery();
            if(rs.next()){
                oCarType.setCartype_Id(Cartype_id);
                oCarType.setName(rs.getString("name"));
                oCarType.setDescription(rs.getString("description"));
            }
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_types.class.getName()).log(Level.SEVERE, null, ex);
        }
          finally{
              return oCarType;
          }
      }
      public ArrayList<Etbl_Car_types> getList_CarType(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
        ArrayList<Etbl_Car_types> arrCarType=new ArrayList<Etbl_Car_types>();
          try {
            clbStm=cnn.prepareCall("{call tbl_Car_types_paged(?,?,?,?,?)}");
               clbStm.setString("OrderBy", orderBy);
                clbStm.setString("TangGiam", ASCorDESC);
                clbStm.setString("WhereClause", WhereClause);
                clbStm.setInt("PageIndex", PagingIndex);
                clbStm.setInt("PageSize", PagingSize);
                rs=clbStm.executeQuery();
                DALTotalPageIndex.getTotalPage("tbl_Car_types", WhereClause, PagingSize);
                while(rs.next()){
                    Etbl_Car_types oCarType= new Etbl_Car_types();
                oCarType.setCartype_Id(rs.getInt("cartype_Id"));
                oCarType.setName(rs.getString("name"));
                oCarType.setDescription(rs.getString("description"));
            }
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_types.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
              return arrCarType;
          }
      }
}
